# coding:utf-8

import time
import thread


def long_io(cb):
    print("开始调用long_Io")
    def fun(callback):
        print("start long_IO")
        time.sleep(2)
        print("end long_IO")
        callback(1)
    thread.start_new_thread(fun, (cb,))
    print("long_Io函数返回")


def on_finish(ret):
    print("调用了回调函数")
    print("ret %s" % ret)
    print("结束回调函数调用")


def req_a():
    print("start calling a")
    long_io(on_finish)
    print("end a")


def req_b():
    print("start b")
    time.sleep(1)
    print("end b")


def main():
    """模拟主循环调度者"""
    req_a()
    req_b()
    while 1:
        pass

if __name__ == "__main__":
    main()